package cn.fay.chapter13;

import java.util.ArrayList;
import java.util.List;

public class InfiniteRecursion {

	public String toString(){
		//此处会发生重复调用。因为在把this转为字符串的时候，会调用它的toString方法，如此会陷入死循环。
		//return "InfiniteRecursion address: "+this+"\n";
		//若想答应出内存地址，得用super.toString()方法，来调用Objec的toString()方法。
		return "InfiniteRecursion address: "+super.toString()+"\n";
	}
	public static void main(String[] args) {
		List<InfiniteRecursion> list=new ArrayList<InfiniteRecursion>();
		for (int i = 0; i <10; i++) 
			list.add(new InfiniteRecursion());
		System.out.println(list);	
		
	}

}
